﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CNVP.Framework.Utils;

namespace CNVP.JShop.Web.Admin.CommonWindows
{
    public partial class AjaxOrderTotal : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string result = Request.QueryString["result"];
            string SaleNum = Request.QueryString["SaleNum"];
            string UserID = Request.QueryString["UserID"];
            if (string.IsNullOrEmpty(UserID) || !Public.IsNumber(UserID))
            {
                UserID = "0";
            }
            if (!string.IsNullOrEmpty(result) && !string.IsNullOrEmpty(SaleNum))
            {
                decimal _SalePrice = 0;

                BLL.CNVP_Products bll_Products = new BLL.CNVP_Products();
                BLL.CNVP_UserLevel bll_UserLevel = new BLL.CNVP_UserLevel();
                BLL.CNVP_ProductsDetail bll_ProductsDetail = new BLL.CNVP_ProductsDetail();

                decimal SalePriceTatol = 0;
                string[] resultArray = result.Split(Convert.ToChar(","));
                for (int i = 0; i < resultArray.Length; i++)
                {
                    string[] SaleNumArray = SaleNum.Split(Convert.ToChar(","));//销售数量
                    string[] IDSArray = resultArray[i].Split(Convert.ToChar("_"));
                    decimal SalePrice_Decimal = 0;
                    if (UserID != "0")
                    {
                        if (IDSArray[1] != "0")
                        {
                            var model_ProductsDetail = bll_ProductsDetail.GetSingle_CNVP_ProductsDetailById(int.Parse(IDSArray[1]));
                            if (model_ProductsDetail != null)
                            {
                                _SalePrice = model_ProductsDetail.SalePrice;
                            }
                        }
                        else
                        {
                            var model_Products = bll_Products.GetSingle_CNVP_ProductsById(int.Parse(IDSArray[0]));
                            if (model_Products != null)
                            {
                                _SalePrice = model_Products.TradePrice;
                            }
                        }

                        int UserLevelID = new BLL.CNVP_Users().GetSingle_CNVP_UsersById(Convert.ToInt32(UserID)).UserLevelID;
                        decimal DisCountPercent = new BLL.CNVP_UserLevel().GetSingle_CNVP_UserLevelById(UserLevelID).DisCountPercent;
                        SalePrice_Decimal = _SalePrice * DisCountPercent;
                    }
                    else
                    {
                        if (IDSArray[1] != "0")
                        {
                            var model_ProductsDetail = bll_ProductsDetail.GetSingle_CNVP_ProductsDetailById(int.Parse(IDSArray[1]));
                            if (model_ProductsDetail != null)
                            {
                                _SalePrice = model_ProductsDetail.SalePrice;
                            }
                        }
                        else
                        {
                            var model_Products = bll_Products.GetSingle_CNVP_ProductsById(int.Parse(IDSArray[0]));
                            if (model_Products != null)
                            {
                                _SalePrice = model_Products.TradePrice;
                            }
                        }
                        SalePrice_Decimal = _SalePrice;
                    }
                    SalePriceTatol += SalePrice_Decimal * int.Parse(SaleNumArray[i]);
                }

                string html = "";
                html += "<h3>支付订单确认</h3>";
                html += "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"  widtd=\"100%\" class=\"division\">";
                html += "		<tr >";
                html += "			<th >";
                html += "				商品总价格：</th>";
                html += "			<td  >";
                html += "			￥<span id=\"spanSalePriceTatol\">" + SalePriceTatol.ToString("f2") + "</span>";
                html += "			<input id=\"inputSalePriceTatol\" type=\"hidden\" name=\"inputSalePriceTatol\" value=\"" + SalePriceTatol.ToString("f2") + "\" /></td>";
                html += "		</tr>";
                html += "		<tr class=\"DeliveryStyle\" style=\"display:none\" >";
                html += "			<th >";
                html += "			   配送费用：</th>";
                html += "			<td  >";
                html += "			￥<span id=\"spanDeliveryPrice\"></span>";
                html += "			<input id=\"inputDeliveryPrice\" type=\"hidden\" name=\"inputDeliveryPrice\" /></td>";
                html += "		</tr>";
                html += "		<tr >";
                html += "			<th>";
                html += "				订单总金额：</th>";
                html += "			<td  >";
                html += "			￥<span id=\"spanOrderTatol\">" + SalePriceTatol.ToString("f2") + "</span>";
                html += "			<input id=\"inputOrderTatol\" type=\"hidden\" name=\"inputOrderTatol\" value=\"" + SalePriceTatol.ToString("f2") + "\" /></td>";
                html += "		</tr>";
                html += "</table>";
                Response.Write(html);
            }
        }
    }
}